package com.homeinns.esserver.exception;

import com.homeinns.esserver.utils.ResultVOUtil;
import com.homeinns.esserver.vo.ResultVO;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @ClassName ExceptionHandle
 * @Description TODO
 * @Author 樊志强
 * @Date 2018/9/30 10:19
 **/
@RestControllerAdvice
public class ExceptionHandle {

    /**
     * 统一处理controller层抛出的异常
     * @param e
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    public ResultVO handle(Exception e){
        //判断异常类型
        if (e instanceof TestUserException){
            TestUserException testUserException = (TestUserException)e;
            return ResultVOUtil.error(testUserException.getCode(), testUserException.getMessage());
        }
        return ResultVOUtil.error(-1, "未知错误");
    }
}
